import { Context } from 'egg'

export default () => async (ctx: Context, next: () => Promise<any>) => {
  try {
    await next()
  } catch (e) {
    const error = e as any
    if (error.status === 401) {
      return ctx.helper.error({ ctx, errType: 'userAuthenticationErr' })
    }
    throw error
  }
}
